// 基础路径 代理地址 是否需要重写
interface apiType {
    base: string,
    target: string,
    rewrite: boolean
}
const base_apis: apiType[] = [
    { base: '/image', target: 'https://www.dmoe.cc', rewrite: true },
    { base: '/360', target: 'http://cdn.apc.360.cn/', rewrite: true },
    { base: '/tr', target: 'https://v2.api-m.com/api', rewrite: true },
    { base: '/tq', target: 'http://ovoa.cc/api/', rewrite: true },
    { base: '/keySearch', target: 'http://wallpaper.apc.360.cn/index.php', rewrite: true },
    { base: '/hot', target: 'http://openbox.mobilem.360.cn/html/api', rewrite: true },
    { base: '/zhihuNews', target: 'https://www.apii.cn', rewrite: true },
    { base: '/daydeo1', target: 'https://api.8uid.cn/', rewrite: true },
    { base: '/lolimi', target: 'https://api.lolimi.cn/API/AI/', rewrite: true },
    { base: '/aal', target: 'https://v.api.aa1.cn/api', rewrite: true },
    { base: '/Bing-Wallpaper-Action', target: 'https://raw.onmicrosoft.cn', rewrite: false },
    { base: '/huangj', target: 'https://api.lolimi.cn/API', rewrite: false },
    { base: '/is15W', target: 'https://api.7trees.cn', rewrite: true },
    { base: '/vvhan', target: 'https://api.vvhan.com/api', rewrite: true },
    { base: '/dailyNews', target: 'https://www.mxnzp.com/api/news', rewrite: true },
    { base: '/google', target: 'https://findmyip.net/api/translate.php', rewrite: true },
    { base: '/common', target: 'https://api.oioweb.cn/api', rewrite: false },
    { base: '/getImages', target: 'https://api.apiopen.top/api', rewrite: false },
    { base: '/apihzBase', target: 'https://cn.apihz.cn', rewrite: true },
    { base: '/mohu', target: 'https://img.moehu.org', rewrite: true },
    { base: '/music', target: 'https://api.cenguigui.cn/api', rewrite: false },
    { base: '/meet', target: 'http://api.yujn.cn/api', rewrite: true },
]
const proxyObj: any = {}

for (const item of base_apis) {
    const baseConfig = {
        target: item.target,
        changeOrigin: true,
    }
    const rewrite = {
        rewrite: (path: string) => {
            let baseUrl = item.base
            let regex = new RegExp(`^${baseUrl}/`)
            return path.replace(regex, '')
        }
    }
    item.rewrite ? proxyObj[item.base] = { ...baseConfig, ...rewrite } : proxyObj[item.base] = baseConfig
}

export default proxyObj
